package com.xuan.yupao.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private Integer code;
    private T data;
    private String message;
    private String description;


    public Result(Integer code, T data, String message, String description) {
        this.code = code;
        this.data = data;
        this.message = message;
        this.description = description;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(0, data, "ok", "");
    }


    public static <T> Result<T> error(ErrorCode errorCode) {
        return new Result<>(errorCode.getCode(), null, errorCode.getErrorMessage(), "");
    }
    public static <T> Result<T> error(ErrorCode errorCode, String description) {
        return new Result<>(errorCode.getCode(), null, errorCode.getErrorMessage(), description);
    }

    public static <T> Result<T> error(Integer code, String message, String description) {
        return new Result<>(code, null, message, description);
    }
}
